package com.qinxueit.yueshu.api;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qinxueit.yueshu.entity.Article;
import com.qinxueit.yueshu.entity.Chapter;
import com.qinxueit.yueshu.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class TaskApi {
    @Autowired
    private ArticleService articleService;

    /**
     * 每隔20秒执行一次
     * 根据小说表的url，爬取具体的章节
     * @throws Exception
     */
    @Scheduled(cron = "0/2 * * * * ?")
    public void run() throws Exception {
        List<Article> articleLists = articleService.list(new QueryWrapper<Article>().select("article_id", "book_url"));
        //System.out.println(articleLists);
        for (Article article : articleLists) {
            if(article.getBookUrl() != null){
                List<Chapter> chapterList = parseHtml.getChapterList(article);

            }
        }
    }
}
